# 1.导入 selenium
from selenium import webdriver

# 2.创建浏览器操作对象
path = 'chromedriver.exe'

browser = webdriver.Chrome(path)

url = 'https://www.baidu.com'
browser.get(url)

# 元素定位
print('元素定位')
# 根据 id 来找到对象
# by_id = browser.find_element_by_id('su')
# print(by_id)

# 根据标签的属性值来匹配
# by_name = browser.find_element_by_name('wd')
# print(by_name)

by_xpath = browser.find_elements_by_xpath('//input[@id="su"]')
print(by_xpath)

by_xpath = browser.find_element_by_xpath('//input[@id="su"]')
print(by_xpath)

# 使用 bs4 的语法来获取对象
css_selector = browser.find_element_by_css_selector('#su')
print(css_selector)

# 查询链接
link_text = browser.find_element_by_link_text('新闻')
print(link_text)

browser.quit()


